package network;
import java.util.Vector;

import network.dataFormats.NetworkData;
import network.dataFormats.PackageType;
public class DummySocket extends RSocket {
	private Vector<NetworkData> queue;
	private DummySocket otherSocket;
	private float speed = 0.1f;
	DummySocket() {
		queue = new Vector<NetworkData>();
	}
	public void sendData(Vector<NetworkData> outgoing) {
		otherSocket.receiveData(outgoing);
	}
	public void sendUnsecure(Vector<NetworkData> outgoing) {
		otherSocket.receiveData(outgoing);
	}
	public void receiveData(Vector<NetworkData> incoming) {
		for (NetworkData d : incoming) {
			NetworkData d2 = new NetworkData(d.data);
			queue.add(d2);
		}
	}
	public Vector<NetworkData> popData() {
		int numGiveOut = Math.min(queue.size(), (int) (queue.size() * speed + 1));
		// Vector<NetworkData> data = (Vector<NetworkData>) queue.clone();
		// Scramble the shit out of the data.
		Vector<NetworkData> data = new Vector<NetworkData>();
		for (int i = 0; i < numGiveOut; i++) {
			int r = (int) (queue.size() * Math.random());
			data.add(queue.get(r));
			queue.remove(r);
		}
		for (NetworkData d : queue) {
			if (d.packages.get(0).header.type == PackageType.SYNCB)
				data.add(d);
		}
		return data;
	}
	public void setOtherSocket(DummySocket s) {
		otherSocket = s;
	}
}
